package org.jtb.quickr;

import java.util.Properties;
import org.apache.log4j.Logger;
import org.jtb.quickr.AuthResponse.Token;
import org.jtb.quickr.ContactsGetListCriteria;

/**
 * Quickr contacts service.
 */
public class ContactsService extends Service {
    private static Logger logger = Logger.getLogger(ContactsService.class.getName());
    
    /**
     * Construct a new quickr contacts service. 
     * Load quickr.properties from the class path.
     * @throws QuickrException If there was a problem constructing this object.
     */
    public ContactsService() throws QuickrException {
        super();
    }
    
    /**
     * Construct a new quickr contacts service based on the given properties.
     * @param properties The quickr properties.
     * @throws QuickrException If a problem occurs constructing this object.
     */
    public ContactsService(Properties properties) throws QuickrException {
        super(properties);
    }

    /**
     * Get contacts. This method will return public and private contacts.
     * For details, see the
     * <a href="http://www.flickr.com/services/api/flickr.contacts.getList.html">
     * flickr.contacts.getList service</a> documentation.
     * @param criteria The contacts get list criteria.
     * @return The contacts response.
     * @throws QuickrException If a problem occurs.
     */
    public ContactsResponse getList(Token authToken, ContactsGetListCriteria criteria) throws QuickrException {
        ContactsGetListRequest cglr = new ContactsGetListRequest(properties.getRestUrl(), properties.getApiKey(), properties.getSecret(), authToken, criteria, properties.getStaticUrl());
        ContactsResponse contacts = cglr.execute();
        
        return contacts;
    }

    /**
     * Get public contacts. This method will only return public contacts.
     * For details, see the
     * <a href="http://www.flickr.com/services/api/flickr.contacts.getPublicList.html">
     * flickr.contacts.getPublicList service</a> documentation.
     * @param criteria The contacts get public list criteria.
     * @return The contacts response.
     * @throws QuickrException If a problem occurs.
     */
    public ContactsResponse getPublicList(ContactsGetPublicListCriteria criteria) throws QuickrException {
        ContactsGetPublicListRequest cgplr = new ContactsGetPublicListRequest(properties.getRestUrl(), properties.getApiKey(), criteria, properties.getStaticUrl());
        ContactsResponse contacts = cgplr.execute();
        
        return contacts;
    }
}
